
function trim(val) { 
	 
	return val.replace(/(^\s*)|(\s*$)/g, "");  
	
} 

function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}





function subForm(){
	
	if(trim(document.getElementById("title").value)=="")
	{
	  alert("品牌名称不能为空！");
	  return;
	} 
	if(document.getElementById("class_id_group").value=="")
	{
			var  class_id_group  ="";
			for( var i=1;i<4;i++)
			{
					if( document.getElementById("class_id"+i).value !="")
					{
						class_id_group += document.getElementById("class_id"+i).value + "|";	
					}
			}
		  
		  if(class_id_group=="")
		  {
		    alert("请选择品牌所属分类！");
			  return;
		  }
		  document.getElementById("class_id_group").value =class_id_group;
  
 }  
  //alert(document.getElementById("class_id_group").value);

	var site_url = document.getElementById("site_url").value; 

	if(trim(site_url)=="")
	{
	  alert("官网地址不能为空！");
	  return;
	} 
	var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
								+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // ftp的user@
								+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
								+ "|" // 允许IP和DOMAIN（域名）
								+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
								+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
								+ "[a-z]{2,6})" // first level domain- .com or .museum
								+ "(:[0-9]{1,4})?" // 端口- :80
								+ "((/?)|" // a slash isn't required if there is no file name
								+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	var re = new RegExp(strRegex);
	if (!re.test(site_url))
	{
				alert("官网地址的格式不正确!");
				return;
  }                                                 
  document.addForm.submit();
} 

function searchForm(){
	
	var class_attr=""; 
  if(document.getElementById("sort1").value!="")
  {
      class_attr = document.getElementById("sort1").value+"|"; 
  }

  if(document.getElementById("sort2").value!="")
  {
      class_attr += document.getElementById("sort2").value+"|"; 
  }

  if(document.getElementById("sort3").value!="")
  {
      class_attr += document.getElementById("sort3").value+"|"; 
  }
  
  document.getElementById("class_attr").value = class_attr;	 
	 
	document.indexForm .submit();
	
}

 function sortNews(val)
 {
    var elem=val.form.elements;
    var all_news_text='';
    for(i=0;i<elem.length;i++)
    {
        if(elem[i].type=="text" && elem[i].id!="s_title" && elem[i].id!="s_cust")
        {
      	   all_news_text +=elem[i].id+','+elem[i].value+'|';
        }
    } 
    document.indexForm.action='/doTradeReg.do';
    document.getElementById("sort").value=all_news_text;
    document.getElementById("bpm_id").value='9538';
    document.indexForm.submit();
 }


var type = "2";

function setSecondClass(val) {
  $("class_id_group").value ="";
	var up_class_id = val;
	Ts_categoryInfo.getCatClassByUpId(up_class_id, type, setSort2);
}

function setSort2(map_data) {
 	DWRUtil.removeAllOptions("sort2");
	DWRUtil.addOptions("sort2", map_data);
	$("sort3").style.display = "none";
	var item = $("sort2").length;
	if (item == 0) {
		$("sort2").style.display = "none";
	} else {
		$("sort2").style.display = "inline";
	}
}
// 设置三级分类
function setTherdClass(val) { 
 
  $("class_id_group").value ="";

	var up_class_id = val;
	
	Ts_categoryInfo.getCatClassByUpId(up_class_id, type, setSort3);
}
function setSort3(map_data) {
  
	if (map_data != null) {
		DWRUtil.removeAllOptions("sort3");
		DWRUtil.addOptions("sort3", map_data);
		var item = $("sort3").length;
		if (item == 0) {
			$("sort3").style.display = "none";
		} else {
			$("sort3").style.display = "inline";
		}
	}
}


function setTypeName1(obj){
	var idx = obj.value;
	$("class_id3").value="";
	$("class_id2").value="";
	$("class_id1").value=idx;
	Ts_categoryInfo.getCatNameById(idx,setClassName1);
}
function setClassName1(val) {
	$("name3").innerHTML = "";
	$("name2").innerHTML = "";
	$("name1").innerHTML = val;
}

function setTypeName2(obj){
	var idx = obj.value;
	$("class_id3").value="";
	$("class_id2").value=idx;
	Ts_categoryInfo.getCatNameById(idx,setClassName2);
}

function setClassName2(val) {
	$("name3").innerHTML = "";
	$("name2").innerHTML = "&nbsp; &gt; " + val + "&nbsp;";
}
function setTypeName3(obj){
	var idx = obj.value;
	$("class_id3").value=idx;
	Ts_categoryInfo.getCatNameById(idx,setClassName3);

	
}
function setClassName3(val) {
	$("name3").innerHTML = "&nbsp; &gt; " + val + "&nbsp;";
}

function checkClass( val )
{
	if( CategoryInfo.checkChildren(val) != 0 )
	{
		alert( "请选择完整类型！" );
		return false;
	}
}

function delIndexInfo(){
	var listsize = document.getElementById('listsize').value;
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	if(pkid_string == ''){
		alert('请至少选择一条!');
		return false;
	}
	document.getElementById('pkid').value = pkid_string;
	document.indexForm.action='/doTradeReg.do';
	if(window.confirm('确认删除吗?')){
		document.indexForm.submit();
	}
}

function delOneNews(val){
	 
    if(window.confirm('确认删除吗?'))
    {
   	  window.location.href='/doTradeReg.do?pkid='+val+'&bpm_id=8260'; 
    } 		
	
}